package com.ideal.manage.esms.controller.alarm;

import com.ideal.manage.esms.bean.DTO.PageDto;
import com.ideal.manage.esms.bean.alarm.Threshold;
import com.ideal.manage.esms.service.alarm.AlarmService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("alarm")
public class ThresholdController {

    @Resource
    private AlarmService alarmService;

    /**
     * 阈值列表请求
     * @param model
     */
    @RequestMapping("threshold_manager")
    public void thresholdList(Model model){

    }

    /**
     *  阈值列表请求
     * @param pageNum
     * @param request
     * @return
     */
    @RequestMapping("threshold_data")
    @ResponseBody
    public PageDto thresholdData(int pageNum, HttpServletRequest request){

        List<Threshold> thresholds = new ArrayList<>();

        Threshold threshold1 = new Threshold();
        threshold1.setValue(4300);
        threshold1.setName("单体过压一级");
        threshold1.setUpdateTime(new Date());
        thresholds.add(threshold1);

        Threshold threshold2 = new Threshold();
        threshold2.setValue(4500);
        threshold2.setName("单体过压二级");
        threshold2.setDiagnose(4500);
        threshold2.setUpdateTime(new Date());
        thresholds.add(threshold2);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(2L);
        pageDto.setRows(thresholds);

        return pageDto;
    }

    /**
     * 阈值修改请求
     * @param id
     * @param model
     */
    @RequestMapping("threshold_edit")
    public void menuEdit(Model model,
                         @RequestParam(value = "id", required = false) Long id){

        Threshold threshold = new Threshold();
        threshold.setName("单体过压一级");
        threshold.setValue(4500);
        model.addAttribute("threshold", threshold);
    }
}
